package Duoxiancheng;
//线程的优先级设置
//setPriority（）设置优先级大小
//getPriority（）获取优先级大小
//MAX_PRIORITY=10最大优先级
//NORM_PRIORITY=5默认优先级
//MIN_PRIORITY=1最小优先级
//Thread.currentThread().getName()方法表示线程的名称
//Thread.currentThread().getPriority()方法表示线程的优先级
public class TestPriority {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());//主线程默认优先级

        MyPriority myPriority=new MyPriority();
        Thread t1=new Thread(myPriority);
        Thread t2=new Thread(myPriority);
        Thread t3=new Thread(myPriority);
        Thread t4=new Thread(myPriority);
        Thread t5=new Thread(myPriority);
        Thread t6=new Thread(myPriority);

        //先设置优先级再运行
        t1.setPriority(2);//优先级为2
        t1.start();

        t2.setPriority(3);//优先级为3
        t2.start();

        t3.setPriority(4);//优先级为4
        t3.start();

        t4.setPriority(Thread.MAX_PRIORITY);//MAX_PRIORITY=10最大优先级
        t4.start();

        t5.setPriority(Thread.NORM_PRIORITY);//NORM_PRIORITY=5
        t5.start();

        t6.setPriority(Thread.MIN_PRIORITY);//MIN_PRIORITY=1
        t6.start();
    }
    public static class MyPriority implements Runnable{

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
            //Thread.currentThread().getName()方法表示线程的名称
            //Thread.currentThread().getPriority()方法表示线程的优先级
        }
    }
}
